package com.cci.kangdao.dao;


import com.cci.kangdao.dao.model.RolesHandleT;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

@MapperScan
public interface RolesHandleTDao {
    int deleteByPrimaryKey(Long id);

    int insert(RolesHandleT record);

    int insertSelective(RolesHandleT record);

    RolesHandleT selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(RolesHandleT record);

    int updateByPrimaryKey(RolesHandleT record);

    /**
     * 查询权限配置的审核人列表信息
     * @param record 请求数据实体，包括companyId，userGroupId，roleId
     * @return
     */
    @Select("select handle.* from RolesHandle_T handle \n" +
            "  inner join User_T users on handle.Flag = 0 and users.Flag = 0 and users.ID = handle.HandlerId\n" +
            "\twhere  handle.CompanyId = #{companyId} and handle.UserGroupId = #{userGroupId} and handle.RoleId = #{roleId}")
    List<RolesHandleT> selectRoleHandlerList(RolesHandleT record);

    @Select("select handle.* from RolesHandle_T handle \n" +
            "  inner join User_T users on handle.Flag = 0 and users.Flag = 0 and users.ID = handle.HandlerId\n" +
            "\twhere  handle.CompanyId in (#{companyIds}) and handle.UserGroupId = #{userGroupId} and handle.RoleId = #{roleId}")
    List<RolesHandleT> selectRoleHandlerListByMap(Map map);

    @Select("<script> select distinct handle.HandlerId from RolesHandle_T handle\n" +
            "inner join User_T users on handle.Flag = 0 and users.Flag = 0 and users.ID = handle.HandlerId\n" +
            "where handle.CompanyId in <foreach collection='companyIds' item='item' open='(' separator=',' close=')'>#{item} </foreach>  and handle.UserGroupId = #{userGroupId} and handle.RoleId = #{roleId} </script>")
    List<Long> selectRoleHandlerIdListByMap(Map map);

    @Select("select * from RolesHandle_T where Flag = 0 and HandlerId = #{handlerId}")
    List<RolesHandleT> selectHandleListByHandlerId(Long handlerId);
}